<?php

namespace app\command;

use app\common\model\Order;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class OrderUpdate extends Command
{
    protected function configure()
    {
        $this->setName('order:update')->setDescription('Update the database records every second.');
    }

    protected function execute(Input $input, Output $output)
    {
        while (true) {
            // 在这里执行你的数据库更新操作
            $res =  Order::where('status',1)->select();
            foreach ($res as $v){
                if(time()>(strtotime($v['create_time']) + 900)){
                    Order::where('id',$v['id'])->update(['status'=>4,'cancel_time'=>datetime(time())]);
                }
            }
            sleep(1); // 休眠1秒钟
        }
    }
}